package com.allwees.bs.c.module.order.repository;

import com.allwees.bs.c.module.base.repository.BaseRepository;
import com.allwees.bs.c.module.order.entity.OrderRefundEntity;
import com.allwees.bs.core.model.order.wf.refund.ERefundState;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

public interface OrderRefundRepository extends BaseRepository<OrderRefundEntity, Integer> {

    @Query("SELECT o FROM OrderRefundEntity o WHERE o.orderUuid in(:orderUuids) AND state in('REFUND_REQUESTED','COMPLETED','REJECTED')")
    List<OrderRefundEntity> getByOrderUuids(@Param("orderUuids")Set<String> orderUuids);

    @Query("SELECT o FROM OrderRefundEntity o WHERE o.uuid = :uuid and isDeleted = 0")
    OrderRefundEntity getOneByUuid(@Param("uuid") String uuid);

    @Query("SELECT count(id) FROM OrderRefundEntity o WHERE o.orderUuid = :orderUuid and isDeleted = 0 AND state = :state")
    int getCountByOrderUuidAndState(@Param("orderUuid") String orderUuid, @Param("state") ERefundState state);

    List<OrderRefundEntity> findAllByUserUuid(String userUuid);

    List<OrderRefundEntity> findAllByOrderUuid(String orderUuid);
}
